<template>
  <div class="positive">
    <el-dialog
      :visible.sync="isShow"
      title="转正"
      width="800px"
      @opened="getData"
    >
      <div class="main">
        <User :userInfo="userInfo"></User>
        <hr />
        <div class="bottom">
          <el-form label-width="100px" :model="form" ref="form" :rules="rules">
            <el-form-item label="转正时间:" prop="dateOfCorrection">
              <el-date-picker v-model="form.dateOfCorrection"></el-date-picker>
            </el-form-item>
            <el-form-item label="转正评价:" prop="correctionEvaluation">
              <el-input
                type="textarea"
                v-model="form.correctionEvaluation"
              ></el-input>
            </el-form-item>
          </el-form>
        </div>
      </div>
      <template #footer>
        <div class="footer">
          <el-button type="primary" @click="submit">提交</el-button>
          <el-button @click="isShow = false"> 取消</el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>

<script>
import { employeesPositive, employeesPositivePut } from '@/api/employees'
import { sysUser } from '@/api/user'
export default {
  name: 'PositiveDialog',
  data () {
    return {
      isShow: false,
      userInfo: '',
      form: {
        dateOfCorrection: '', //	string	非必须		转正日期format: date-time
        correctionEvaluation: '', //	string	非必须		转正评价
        createTime: '', //	string	非必须		创建时间format: date-time
        enclosure: '', //	string	非必须		附件
        estatus: '', //	integer	非必须		状态 1是未执行，2是已执行format: int32
        userId: '' //	string	非必须		员工ID
      },
      rules: {
        dateOfCorrection: [
          { required: true, message: '必填', trigger: 'change' }
        ],
        correctionEvaluation: [
          { required: true, message: '必填', trigger: 'change' }
        ]
      }
    }
  },
  watch: {
    isShow: {
      handler (newVal) {
        if (!newVal) {
          this.$refs.form.resetFields()
          this.form = {
            dateOfCorrection: '', //	string	非必须		转正日期format: date-time
            correctionEvaluation: '' //	string	非必须		转正评价
          }
        }
      }
    }
  },
  methods: {
    async getData () {
      const result = await sysUser(this.form.userId)
      const res = await employeesPositive(this.form.userId)
      this.userInfo = result.data
      this.form = res.data
      console.log('个人信息', result)
      console.log('转正信息', res)
    },
    // 转正提交
    submit () {
      this.$refs.form.validate(async res => {
        if (res) {
          await employeesPositivePut(this.form)
          this.$message.success('提交成功')
          this.isShow = false
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
::v-deep .el-textarea {
  width: 400px;
}
.footer {
  text-align: center;
}
</style>
